{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 79,
   "id": "6c1eeb0d",
   "metadata": {},
   "outputs": [],
   "source": [
    "from numpy import matrix as mx\n",
    "from numpy import ravel"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 80,
   "id": "fe996141",
   "metadata": {},
   "outputs": [],
   "source": [
    "def matrixUngrapper(my_matrix):\n",
    "    (n,m)=my_matrix.shape\n",
    "    for i in range(n):\n",
    "        for j in range(m):\n",
    "            yield my_matrix[i,j]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 88,
   "id": "82df1763",
   "metadata": {},
   "outputs": [],
   "source": [
    "A = mx([[3,4,5],[9,6,3],[2,8,5]])\n",
    "el_list = []\n",
    "el_dict = dict()\n",
    "i = 0\n",
    "for cell in matrixUngrapper(A):\n",
    "    el_list.append(cell)\n",
    "    i+=1\n",
    "    el_dict[i]=cell"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 89,
   "id": "891a2a68",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[3 4 5]\n",
      " [9 6 3]\n",
      " [2 8 5]]\n",
      "[3, 4, 5, 9, 6, 3, 2, 8, 5]\n",
      "{1: 3, 2: 4, 3: 5, 4: 9, 5: 6, 6: 3, 7: 2, 8: 8, 9: 5}\n",
      "[[3 4 5 9 6 3 2 8 5]]\n",
      "[3 4 5 9 6 3 2 8 5]\n"
     ]
    }
   ],
   "source": [
    "print(A)\n",
    "print(el_list)\n",
    "print(el_dict)\n",
    "print(A.flatten())\n",
    "print(ravel(A))\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "47319059",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
